#include "utypes.h"
#include "video-text.h"
#include <go32.h>
#include <sys/farptr.h>
#include <dpmi.h>
#include <string.h>
#include <stdlib.h>	

Bool printCharAt(char ch, int x, int y, char attributes)
{
		if(x<WIDTH && y<600) 
		{
		offset l = y*(80*2)+(x*2);
		_farpokeb(_dos_ds, VIDEO_TEXT + l, ch );
		_farpokeb(_dos_ds, VIDEO_TEXT + l + 1, attributes); /* attribute byte: 0100 0001b */
		
		return 1;
		}
		else { return 0;}
}

void desenhaSnake(int x, int y, char attributes){
              
char l1[] ={"                  ueeeeeu..^**$e.                      "};                       
char l2[] ={"                ur d$$$$$$$$$$$$$$Nu **Nu              "};                    
char l3[] ={"               d$$$ *$$$$$$$$$$$$$$$$$$e.*$c           "};                  
char l4[] ={"          u$$ckkupl**^*^**$$$$$$$$$$$$$b.^R:           "};               
char l5[] ={"        z$$#***           `!?$$$$$$$$$$$$$N.^          "};              
char l6[] ={"      .$P                   ~!R$$$$$$$$$$$$$b          "};            
char l7[] ={"    x$F                 **$b. '*R).$$$$$$$$$$          "};          
char l8[] ={"   J^*                           #$$$$$$$$$$$$.        "};        
char l9[] ={"  z$e                      ..      ***$$$$$$$$$        "};       
char l10[] ={"  :$P           .        .$$$$$b.    ..  *  #$$$$      "};     
char l11[] ={"  $$            L          ^*$$$$b   *      4$$$$L     "};   
char l12[] ={" 4$$            ^u    .e$$$$e.**$$$N.       @$$$$$     "}; 
char l13[] ={" $$E            d$$$$$$$$$$$$$$L *$$$$$  mu $$$$$$F    "};
char l14[] ={" $$&            $$$$$$$$$$$$$$$$N   *#* * ?$$$$$$$N    "};
char l15[] ={" $$F            '$$$$$$$$$$$$$$$$$bec...z$ $$$$$$$$    "};
char l16[] ={"'$$F             `$$$$$$$$$$$$$$$$$$$$$$$$ '$$$$E*$    "};
char l17[] ={" $$$$                ^******`       ^**$$$& 9$$$$N     "};
char l18[] ={" kpku$                                  *$$. *$$P r    "};
char l19[] ={" 4$$$$L                                   *$. eeeR     "};
char l20[] ={"   $$$$$k                                   '$e. .@    "};
char l21[] ={"   3$$$$$b                                   '$$$$     "};
char l22[] ={"    $$$$$$$                                   3$$      "};
char l23[] ={"     $$$$$$$dc                                4$F      "};
char l24[] ={"      RF** <$$$44                             J        "};
char l25[] ={"       #bue$$$LJ$$$Nc.                        *        "};

	
	printStringAt(l1, x, y, attributes);
	printStringAt(l2, x, y+1, attributes);
	printStringAt(l3, x, y+2, attributes);
	printStringAt(l4, x, y+3, attributes);
	printStringAt(l5, x, y+4, attributes);
	printStringAt(l6, x, y+5, attributes);
	printStringAt(l7, x, y+6, attributes);
	printStringAt(l8, x, y+7, attributes);
	printStringAt(l9, x, y+8, attributes);
	printStringAt(l10, x, y+9, attributes);
	printStringAt(l11, x, y+10, attributes);
	printStringAt(l12, x, y+11, attributes);
	printStringAt(l13, x, y+12, attributes);
	printStringAt(l14, x, y+13, attributes);
	printStringAt(l15, x, y+14, attributes);
	printStringAt(l16, x, y+15, attributes);
	printStringAt(l17, x, y+16, attributes);
	printStringAt(l18, x, y+17, attributes);
	printStringAt(l19, x, y+18, attributes);
	printStringAt(l20, x, y+19, attributes);
	printStringAt(l21, x, y+20, attributes);
	printStringAt(l22, x, y+21, attributes);
	printStringAt(l23, x, y+22, attributes);
	printStringAt(l24, x, y+23, attributes);
	printStringAt(l25, x, y+24, attributes);
}

void cls(char c, char attrib) {

	int i, j;
	for(i = 0; i < WIDTH; ++i)
		for(j = 0; j < HEIGHT; ++j)
			printCharAt(c,i,j,attrib);

}

Bool printStringAt(char *str, int x, int y, char attributes)
{
	unsigned int i;
	int tam = strlen(str);
	
		if(x<WIDTH && y<HEIGHT) 
		{
			for(i=0; i<tam; i++)
			{
				printCharAt(str[i], x+i, y, attributes);
			}
			return 1;
		}
		else { return 0;}
	
}

Bool printIntAt(int num, int x, int y, char attributes)
{
	char *a;
	a=malloc(sizeof(char)*3);
	itoa (num, a, 10);
	
		if(x<WIDTH && y<HEIGHT) 
		{
			printStringAt(a, x, y, attributes);
			return 1;
		}
		else { return 0;}
}

